import { BasicColumn, FormSchema } from '/@/components/Table';
import { render } from '/@/utils/common/renderUtils';
import { DescItem } from '/@/components/Description/index';
import { useI18n } from '/@/hooks/web/useI18n';
import { listAllPayIfDefine } from '../payIfDefine/payIfDefine.api'
const { t } = useI18n('');

export const columns: BasicColumn[] = [
  {
    title: t('对账批次号'),
    dataIndex: 'batchNo',
    fixed: 'left',
    width: 260,
  },
  {
    title: t('账单日期'),
    dataIndex: 'billDate',
    width: 130,
  },
  {
    title: t('支付接口'),
    dataIndex: 'ifCode',
    width: 130,
  },
  {
    title: t('解析失败原因'),
    dataIndex: 'parseErrorMsg',
    width: 120,
  },
  {
    title: t('解析状态'),
    dataIndex: 'parseStatusText',
    width: 100,
    customRender: ({ record }) => {
      const { parseStatusText, parseStatus } = record as any
      let color = 'green'
      if (parseStatus === '2') {
        color = 'red'
      }
      return render.renderTag(parseStatusText, color)
    }
  },
  {
    title: t('处理状态'),
    dataIndex: 'statusText',
    width: 100,
    customRender: ({ record }) => {
      const { statusText, status } = record as any
      let color = 'orange'
      if (status === '2') {
        color = 'green'
      }
      return render.renderTag(statusText, color)
    }
  },
 
  {
    title: t('创建时间'),
    dataIndex: 'createdAt',
    width: 150,
    align: 'center',
  }
];

export const searchFormSchema: FormSchema[] = [
  {
    label: t('账单日期'),
    field: 'billDate',
    component: 'RangePicker',
    componentProps: {
      valueType: 'Date',
    },
  },
  {
    label: t('对账批次号'),
    field: 'batchNo',
    component: 'Input',
  },
  {
    label: t('支付接口'),
    field: 'ifCode',
    component: 'ApiSelect',
    componentProps: {
      api: listAllPayIfDefine,
      showSearch: true,
      allowClear: true,
      placeholder: '全部',
      resultField: 'data',
      labelField: 'ifName',
      valueField: 'ifCode',
    },
  },
  {
    label: t('解析状态'),
    field: 'parseStatus',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: 'pay_check_batch_parse_status',
      placeholder: '全部',
      chooseOptionLabel: '全部',
      allowClear: true,
    },
  },
  {
    label: t('处理状态'),
    field: 'status',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: 'pay_check_batch_handle_status',
      placeholder: '全部',
      chooseOptionLabel: '全部',
      allowClear: true,
    },
  },
];

export const formDetailSchema: DescItem[] = [
  {
    label: t('对账批次号'),
    field: 'batchNo',
    span: 2
  },
  {
    label: t('账单日期'),
    field: 'billDate'
  },
  {
    label: t('商户应用ID'),
    field: 'appId'
  },

  {
    label: t('平台商户号'),
    field: 'mchNo'
  },
  {
    label: t('渠道商户号'),
    field: 'channelMchNo'
  },
  {
    label: t('支付接口'),
    field: 'ifCode'
  },
  {
    label: t('创建时间'),
    field: 'createdAt'
  },
  {
    label: t('更新时间'),
    field: 'updatedAt'
  },
  {
    label: t('更新者'),
    field: 'updatedBy'
  },
  {
    label: t('账单地址'),
    field: 'channelBillUrl',
    show: (channelBillUrl) => channelBillUrl,
    render: (curVal, data) => {
      return render.renderHref({ url: curVal, text: '下载' })
    }
  },
  {
    label: t('批次跟踪ID'),
    field: 'tradeId'
  },
  {
    field: 'parseStatus',
    label: t('解析状态'),
    render: (curVal, data) => {
      const color = curVal === '1' ? 'green' : 'red';
      return render.renderTag(render.renderDict(curVal, 'pay_check_batch_parse_status'), color)
    }
  },
  {
    field: 'status',
    label: t('处理状态'),
    // labelStyle: { width: '80px' },
    render: (curVal, data) => {
      const color = curVal === '1' ? 'orange' : 'green';
      return render.renderTag(render.renderDict(curVal, 'pay_check_batch_handle_status'), color)
    }
  },

  {
    label: t('解析失败原因'),
    field: 'parseErrorMsg',
    render: (curVal, data) => {
      return render.renderInputTextArea({
        value: curVal,
        autoSize: {
          minRows: 3,
          maxRows: 8
        },
        readOnly: true
      })
    },
    span: 2
  },
  {
    label: '',
    field: 'drivider',
    render: (curVal, data) => {
      return render.renderDividerWithValue('批次数据')
    },
    span: 2
  },
  {
    label: t('差异总数'),
    field: 'diffCount'
  },
  {
    label: t('待处理的差异总数'),
    field: 'unHandleDiffCount'
  },
  {
    label: t('平台交易总数'),
    field: 'totalCount'
  },
  {
    label: t('渠道交易总数'),
    field: 'channelTotalCount'
  },
  {
    label: t('平台交易总金额'),
    field: 'totalAmount'
  },
  {
    label: t('渠道交易总金额'),
    field: 'channelTotalAmount'
  },
  {
    label: t('平台总退款总数'),
    field: 'totalRefundCount'
  },
  
  {
    label: t('渠道退款总数'),
    field: 'channelTotalRefundCount'
  },

  {
    label: t('平台总退款总金额'),
    field: 'totalRefundAmount'
  },
  {
    label: t('渠道退款总金额'),
    field: 'channelTotalRefundAmount'
  },

  {
    label: t('平台总手续费'),
    field: 'totalFee'
  },
  {
    label: t('渠道总手续费'),
    field: 'channelTotalFee'
  },

];
